package com.codeing.demo.redis.redission.service;

import com.codeing.demo.utils.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**QQ群初始化
 * @auther zzyy
 * @create 2021-05-23 17:59
 */
@Service
@Slf4j
public class TaskQQCrowdService
{

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *提前先把数据刷新到redis缓存中。QQ群
     */
//    @PostConstruct
    public void init(){
        log.info("启动初始化各种QQ群..........");
        List<String> crowds=this.crowd();
        this.redisTemplate.delete(Constants.CROWD_KEY);
        crowds.forEach(t->this.redisTemplate.opsForSet().add(Constants.CROWD_KEY,t));
    }

    /**
     * 模拟100个热门群，用于推荐
     */
    public List<String> crowd() {
        List<String> list=new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Random rand = new Random();
            int id= rand.nextInt(10000);
            list.add("群"+id);
        }
        return list;
    }
}

